package m3;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 连接
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("wht6.cn"); // 192.168.64.140
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        Channel c = f.newConnection().createChannel();

        // 创建 fanout 类型交换机： logs
        // c.exchangeDeclare("logs", "fanout", false, false, null);
        c.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);

        // 循环数据消息，发送
        while (true) {
            System.out.print("输入消息：");
            String s = new Scanner(System.in).nextLine();
            // 对 fanout 交换机，第二个参数无效
            c.basicPublish("logs", "", null, s.getBytes());
        }
    }
}
